import 'dart:io';

import 'package:dbio_utils/generic_filehandle/local_file.dart';
import 'package:dbio_utils/tabix/csi.dart';
import 'package:dbio_utils/tabix/tbi.dart';
import 'package:dbio_utils/tabix/virtual_offset.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('tbi test', () async {
    var file = LocalFile(File('test/tabix/data/volvox.test.vcf.gz.tbi'));
    final tbi = TabixIndex(fileHandle: file);
    var indexData = await tbi.parse({});
    print(indexData);

    expect(indexData['columnNumbers']['start'], 2);
    expect(indexData['columnNumbers']['ref'], 1);
    expect(indexData['columnNumbers']['end'], 0);

    var blocks = await tbi.blocksForRange(refName: 'contigA', start: 1, end: 4000);
    print(blocks);
    expect(blocks.length, 1);
    expect(blocks[0].minv.blockPosition, 0);
    expect(blocks[0].minv.dataPosition, 10431);

    var meta = await tbi.getMetadata({});
    print(meta);
    expect(meta, {
      'columnNumbers': {'end': 0, 'ref': 1, 'start': 2},
      'coordinateType': '1-based-closed',
      'format': 'VCF',
      'metaChar': '#',
      'maxBinNumber': 37449,
      'firstDataLine': VirtualOffset(0, 10431),
      'refIdToName': ['contigA'],
      'refNameToId': {'contigA': 0},
      'maxBlockSize': 1 << 16,
      'skipLines': 0,
      'maxRefLength': 536870912,
    });

    expect([], await tbi.blocksForRange(refName: 'contigA', start: 7334998796, end: 8104229566));
  });
}
